﻿using LightOMator.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace LightOMator.Converter
{
    public class FadeCollectionToBrushConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            FadeCollection collection = (FadeCollection)value;
            LinearGradientBrush brush = new LinearGradientBrush
            {
                StartPoint = new Point(0, 0.5),
                EndPoint = new Point(1, 0.5)
            };
            for (int fadeIndex = 0; fadeIndex < collection.Fades.Count; fadeIndex++)
            {
                Fade fade = collection.Fades[fadeIndex];
                brush.GradientStops.Add(new GradientStop
                {
                    Color = fade.Color,
                    Offset = (fadeIndex * 1.0) / collection.Fades.Count
                });
            }
            return brush;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
